<template>
  <el-row
    :gutter="option.gutter || 10"
    class="panel-group"
  >
    <el-col
      v-for="(view, viewIndex) in items"
      :key="viewIndex"
      :span="span"
      class="card-panel-col"
    >
      <el-container class="card-panel">
        <el-aside width="25%">
          <div class="card-panel-icon-wrapper center" :class="`card-panel-${viewIndex}`">
            <svg-icon
              :icon-class="view.icon"
              class-name="card-panel-icon"
            />
          </div>
        </el-aside>
        <el-container v-if="view.content && Array.isArray(view.content)">
          <el-header height="40%">
            <div class="card-panel-title center">
              <span>{{ view.title }}</span>
            </div>
          </el-header>
          <el-main class="card-panel-content">
            <el-row style="height: 100%">
              <el-col
                v-for="(item, itemIndex) in view.content"
                :key="itemIndex"
                :span="24 / (view.content ? view.content.length : 1)"
                style="height: 100%"
                class="center"
              >
                <div>
                  <div class="card-panel-text">
                    {{ item.text }}
                  </div>
                  <count-to
                    :start-val="0"
                    :end-val="item.count"
                    :duration="2600"
                    class="card-panel-num"
                  />
                </div>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
        <el-main v-else class="center">
          <div class="card-panel-content-singer">
            <div class="card-panel-text">
              <span>{{ view.title }}</span>
            </div>
            <div class="card-panel-num center">
              {{ view.content }}{{ view.unit }}
            </div>
          </div>
        </el-main>
      </el-container>
    </el-col>
    <!--    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" style="padding-right:0px;">-->
    <!--      <div class="card-panel" @click="handleSetLineChartData('newVisitis')">-->
    <!--        <div class="card-panel-icon-wrapper icon-people">-->
    <!--          <svg-icon icon-class="peoples" class-name="card-panel-icon"/>-->
    <!--        </div>-->
    <!--        <div class="card-panel-content">-->
    <!--          <div class="card-panel-text">-->
    <!--            访客-->
    <!--          </div>-->
    <!--          <count-to :start-val="0" :end-val="102400" :duration="2600" class="card-panel-num"/>-->
    <!--        </div>-->
    <!--      </div>-->
    <!--    </el-col>-->
    <!--    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" style="padding-right:0px;padding-left:12px">-->
    <!--      <div class="card-panel" @click="handleSetLineChartData('messages')">-->
    <!--        <div class="card-panel-icon-wrapper icon-message">-->
    <!--          <svg-icon icon-class="message" class-name="card-panel-icon"/>-->
    <!--        </div>-->
    <!--        <div class="card-panel-content">-->
    <!--          <div class="card-panel-text">-->
    <!--            消息-->
    <!--          </div>-->
    <!--          <count-to :start-val="0" :end-val="81212" :duration="3000" class="card-panel-num"/>-->
    <!--        </div>-->
    <!--      </div>-->
    <!--    </el-col>-->
    <!--    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" style="padding-right:0px;padding-left:12px">-->
    <!--      <div class="card-panel" @click="handleSetLineChartData('purchases')">-->
    <!--        <div class="card-panel-icon-wrapper icon-money">-->
    <!--          <svg-icon icon-class="money" class-name="card-panel-icon"/>-->
    <!--        </div>-->
    <!--        <div class="card-panel-content">-->
    <!--          <div class="card-panel-text">-->
    <!--            金额-->
    <!--          </div>-->
    <!--          <count-to :start-val="0" :end-val="9280" :duration="3200" class="card-panel-num"/>-->
    <!--        </div>-->
    <!--      </div>-->
    <!--    </el-col>-->
    <!--    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" style="padding-left:12px;">-->
    <!--      <div class="card-panel" @click="handleSetLineChartData('shoppings')">-->
    <!--        <div class="card-panel-icon-wrapper icon-shopping">-->
    <!--          <svg-icon icon-class="shopping" class-name="card-panel-icon"/>-->
    <!--        </div>-->
    <!--        <div class="card-panel-content">-->
    <!--          <div class="card-panel-text">-->
    <!--            订单-->
    <!--          </div>-->
    <!--          <count-to :start-val="0" :end-val="13600" :duration="3600" class="card-panel-num"/>-->
    <!--        </div>-->
    <!--      </div>-->
    <!--    </el-col>-->
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  components: {
    CountTo
  },
  props: {
    option: {
      type: Object, default() {
        return {}
      }
    }
  },
  data() {
    return {
      colors: ['#32DADD', '#C8B2F4', '#63C2FF', '#FFCB8C', '#FF915A', '#FF7070'],
      span: 24,
      items: []
    }
  },
  created() {
    const option = this.option
    this.span = option.span ? option.span : 24 / option.data.length
    this.items = this.option.data.map(v => {
      v.hover = false
      return v
    })
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

.center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel-group {
  /*margin-top: 12px;*/

  .card-panel-col {
    margin-bottom: 12px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    //&:hover {
    //  .card-panel-icon-wrapper {
    //    /*color: #FFF;*/
    //    background-color: #eee;
    //  }
    //
    //}

    .card-panel-icon-wrapper {
      width: calc(100% - 32px);
      height: calc(100% - 32px);
      margin: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;

    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-title {
      width: 100%;
      height: 100%;
      color: rgba(0, 0, 0, 0.45);
      font-size: 20px;
      font-weight: bold;
    }

    .card-panel-content {
      font-weight: bold;
      .card-panel-text {
        color: rgba(0, 0, 0, 0.45);
        font-size: 14px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 16px;
      }
    }
    .card-panel-content-singer {
      font-weight: bold;
      .card-panel-text {
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
.card-panel-0 {
  background-color: #fff;
  .svg-icon {
    color: #32DADD;
  }
  &:hover {
    background-color: #32DADD;
    .svg-icon {
    color: #fff;
  }
  }
}
.card-panel-1 {
  background-color: #fff;
  .svg-icon {
    color: #C8B2F4;
  }
  &:hover {
    background-color: #C8B2F4;
    .svg-icon {
    color: #fff;
  }
  }
}
.card-panel-2 {
  background-color: #fff;
  .svg-icon {
    color: #63C2FF;
  }
  &:hover {
    background-color: #63C2FF;
    .svg-icon {
    color: #fff;
  }
  }
}
.card-panel-3 {
  background-color: #fff;
  .svg-icon {
    color: #FFCB8C;
  }
  &:hover {
    background-color: #FFCB8C;
    .svg-icon {
    color: #fff;
  }
  }
}
.card-panel-4 {
  background-color: #fff;
  .svg-icon {
    color: #FF915A;
  }
  &:hover {
    background-color: #FF915A;
    .svg-icon {
    color: #fff;
  }
  }
}
.card-panel-5 {
  background-color: #fff;
  .svg-icon {
    color: #FF7070;
  }
  &:hover {
    background-color: #FF7070;
    .svg-icon {
    color: #fff;
  }
  }
}

@media (max-width: 550px) {
  .card-panel-content {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.el-aside, .el-main, .el-header {
  padding: 0;
  margin: 0;
  background-color: #FFF;
}
</style>
